﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Silverlight3dApp.Learning.Lesson07
{
    public class BasicModel
    {
        protected Model _Model;

        public Model Model
        {
            get
            {
                return _Model;
            }
        }

        protected Matrix _World = Matrix.Identity;

        public virtual Matrix World
        {
            get
            {
                return _World;
            }
        }

        public BasicModel(Model model)
        {
            _Model = model;
        }

        public virtual void Update()
        {
        }

        public void Draw(Camera camera)
        {
            //var copiedBonesTransforms = new Matrix[_Model.Bones.Count];
            //_Model.CopyAbsoluteBoneTransformsTo(copiedBonesTransforms);

            foreach (var mesh in _Model.Meshes)
            {
                foreach (BasicEffect basicEffect in mesh.Effects)
                {
                    basicEffect.EnableDefaultLighting();
                    basicEffect.World = World * mesh.ParentBone.Transform;
                    basicEffect.Projection = camera.Projection;
                    basicEffect.View = camera.View;
                }
                mesh.Draw();
            }
        }
    }
}